<!DOCTYPE HTML>
<html>
<head>
    <title>104_writeFileDemo</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
</head>
<body>
	<input type="button" id="btn01" value="click" onclick="clickMe();" />
<script type="text/javascript">
	/*
	 * 这样写是不行的,必须放到nodejs环境中(比如使用node命令启动)
	 * 报错: Uncaught ReferenceError: require is not defined
	 */
	function clickMe(){
		var fs = require('fs');
		fs.writeFile('./test2.txt', 'test test', function(err) {
			if(err){
				throw err;
			}
			console.log('Saved.');
			fs.readFile('./test2.txt', 'utf-8', function(err, data) {
				if(err){
					throw err;
				}
				console.log(data);
			});
		});
	}
</script>
</body>
</html>